package com.studycloud.controller;

import com.studyclud.entity.Payment;
import com.studyclud.result.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

import static com.studyclud.constant.ConstantUrl.PAYMENT_URL;

/**
 * @author JP
 */
@RestController
@Slf4j
public class OrderController
{

    @Resource
    private RestTemplate restTemplate;

    @GetMapping(value = "/consumer/payment/zk")
    public String paymentzk()
    {
        return restTemplate.getForObject("HTTP://"+PAYMENT_URL+"/payment/zk",String.class);
    }

    @GetMapping(value = "/consumer/payment/create")
    public CommonResult<Payment> create(Payment payment)
    {
        return restTemplate.postForObject("HTTP://"+PAYMENT_URL+"/zookeeper/payment/create",payment,CommonResult.class);
    }

    @GetMapping(value = "/consumer/payment/getPaymenById/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id)
    {
        return restTemplate.getForObject("HTTP://"+PAYMENT_URL+"/zookeeper/payment/getPaymenById/"+id,CommonResult.class);
    }
}
